#include <sstream>
#include "DinamicAnimation.h"

int DinamicAnimation::max_dir=4;
//------------------------------------------------------------
float DinamicAnimation::move_speed=0.15;
//------------------------------------------------------------
DinamicAnimation::DinamicAnimation(string name, int num_frame):StaticAnimation(name, num_frame){
    setRandomDirection();
}
//-----------------------------------------------------------------------------
void DinamicAnimation::setDirection(char d){
    switch(d){
        case 'u':
            cur_dir = 2;
            break;
        case 'd':
            cur_dir = 0;
            break;
        case 'l':
            cur_dir = 1;
            break;
        case 'r':
            cur_dir = 3;
            break;
    }
}
//-----------------------------------------------------------------------------
void DinamicAnimation::setRandomDirection(){
    cur_dir = rand()%4;
}
//-----------------------------------------------------------------------------
char DinamicAnimation::getDirection(){
    switch(cur_dir){
        case 2:
            return 'u';
            break;
        case 0:
            return 'd';
            break;
        case 1:
            return 'l';
            break;
        case 3:
            return 'r';
            break;
    }
}
//-----------------------------------------------------------------------------
void DinamicAnimation::moveX(int k, float time){
    x += move_speed*k*time;
}
//-----------------------------------------------------------------------------
void DinamicAnimation::moveY(int k, float time){
    y += move_speed*k*time;
}
//-----------------------------------------------------------------------------
string DinamicAnimation::getFramePath(){
    std::ostringstream ss;
    ss << (int)cur_frame;
    string direction;

    switch(cur_dir){
        case 0:
            direction = "_down";
            break;
        case 1:
            direction = "_left";
            break;
        case 2:
            direction = "_up";
            break;
        case 3:
            direction = "_right";
            break;
    }
    return name + direction + ss.str() + ".png";
}
